<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8"	contentType="text/html; charset=utf-8"%>
<%@include file="/quick/include/common.jsp"%>
<c:set var="buttons">
	<input type="button" style="margin-right: 5px" onclick="f_add()"		value="<fmt:message key="button.add"/>" />
	<input type="button" style="margin-right: 5px" onclick="f_update()"		value="<fmt:message key="button.update"/>" />
	<input type="button" style="margin-right: 5px" onclick="f_delete()"		value="<fmt:message key="button.delete"/>" />
	<input type="button" style="margin-right: 5px" onclick="f_cancel()"		value="<fmt:message key="button.cancel"/>" />
	<input type="button" style="margin-right: 5px" onclick="f_save()"		value="<fmt:message key="button.save"/>" />
    <input type="button" style="margin-right: 5px"   onclick="f_read()" value="<fmt:message key="button.view"/>"/>
	<input type="button" style="margin-right: 5px" onclick="f_query()"		value="<fmt:message key="button.query"/>" />
	<input type="button" style="margin-right: 5px" onclick="f_fields()"		value="<fmt:message key="button.field"/>" />
	<input type="button" style="margin-right: 5px" onclick="f_test()"		value="<fmt:message key="button.test"/>" />
	<input type="button" style="margin-right: 5px" onclick="f_back()"		value="<fmt:message key="button.back"/>" />
</c:set>
<div id='toolbar' style="display:none">
	<c:out value="${buttons}" escapeXml="false" />
</div>

<c:set var="buttons">
	<input type="button" style="margin-right: 5px" onclick="f_add('COLUMN_DEF_ALIAS')"		value="<fmt:message key="button.add"/>" />
	<input type="button" style="margin-right: 5px" onclick="f_update('COLUMN_DEF_ALIAS')"		value="<fmt:message key="button.update"/>" />
	<input type="button" style="margin-right: 5px" onclick="f_delete('COLUMN_DEF_ALIAS')"		value="<fmt:message key="button.delete"/>" />
	<input type="button" style="margin-right: 5px" onclick="f_cancel('COLUMN_DEF_ALIAS')"		value="<fmt:message key="button.cancel"/>" />
</c:set>
<div id='subToolbar' style="display:none">
	<c:out value="${buttons}" escapeXml="false" />
</div>





<script>
Ext.onReady(globalScope._ready);
Ext.onReady(function(){
  globalScope.grid.get("TABLE_DEF_ALIAS").on('rowdblclick',f_cascadeUpdate);
});


function f_read(){
  globalScope._view();
}
function f_cascadeUpdate(){
  var mainTable='TABLE_DEF_ALIAS';
  var subTable='COLUMN_DEF_ALIAS';
  var grid=globalScope.grid.get(mainTable);
  var r=grid.getSelectionModel().getSelected();
  if(Ext.isEmpty(r)){
    Ext.Msg.alert('WARNING','请选择记录');
    return;
  }
  var table=r.get("TABLENAME");
  var tableAlias=r.get("TABLEALIAS");
  globalScope.opt.add(mainTable,'cascadeUpdt');
  globalScope._cascade(mainTable,subTable,{tableName:subTable,OWNTABLEALIAS:tableAlias,OWNTABLE:table},r);
}


function f_back(){
   history.back();
}

function f_test(){
  var r=globalScope.grid.get("TABLE_DEF_ALIAS").getSelectionModel().getSelected();
  if(Ext.isEmpty(r)){
    Ext.Msg.alert('WARNING','请选择数据表');
    return;
  }
  var table=r.get("TABLENAME");
   var matrix=[["tableName",table]];
   var form=createForm("<c:url value='/quick/quick.html'/>",matrix);
   form.submit();   
   
}


function f_add(tableName){
  globalScope._add(tableName);
}

function f_update(tableName){
  globalScope._update(tableName);
}

function f_delete(tableName){
  globalScope._delete(tableName);
} 

function f_cancel(tableName){
  globalScope._cancel(tableName);
}

function f_save(tableName,url){
  globalScope._save(tableName,url);
}

function f_query(tableName){
    globalScope._query(tableName);
}

function f_gotoPage(pageNo,rowsOfPage,pageCount,rowCount,conditoin){
  globalScope._gotoPage({spanName:"g_pageSpan_<c:out value='${model.tableName}'/>",pageNo:pageNo,rowsOfPage:rowsOfPage,pageCount:pageCount,rowCount:rowCount,condition:conditoin,tableName:"<c:out value='${model.tableName}'/>"});
}


function f_fields(){
  var r=globalScope.grid.get("TABLE_DEF_ALIAS").getSelectionModel().getSelected();
  if(Ext.isEmpty(r)){
    Ext.Msg.alert('WARNING','请选择数据表');
    return;
  }
  var table=r.get("TABLENAME");
  var tableAlias=r.get("TABLEALIAS");
   var matrix=[["tableName","COLUMN_DEF_ALIAS"],["OWNTABLEALIAS",tableAlias],["OWNTABLE",table]];
   var form=createForm("<c:url value='/quick/quick.html'/>",matrix);
   form.submit();   
   
}
</script>
